package cn.jqq.org.service.impl;

import cn.jqq.basic.PageList;
import cn.jqq.org.domain.Department;
import cn.jqq.org.mapper.DepartmentMapper;
import cn.jqq.org.query.DepartmentQuery;
import cn.jqq.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public Department findOne(Long id) {
        return departmentMapper.findOne(id);
    }

    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery departmentQuery) {
        //查询总条数
        Long count = departmentMapper.queryCount();
        //查询分页
        List<Department> departments = departmentMapper.queryData(departmentQuery);
        //封装
        return new PageList<>(count,departments);
    }


}
